# The isBadVersion API is already defined for you.
# @param version, an integer
# @return an integer
# def isBadVersion(version):

class Solution:
    def firstBadVersion(self, n):
        """
        :type n: int
        :rtype: int
        """
        begin = 0
        end = n
        while begin < end:
            mid = (begin +end)//2
            if isBadVersion(mid):
                end = mid
            else:
                begin = mid + 1
        return begin
